package com.huaxin.device.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.huaxin.device.dto.ResponseResult;
import com.huaxin.device.dto.request.CollectedDataRecordCreateReqDTO;
import com.huaxin.device.dto.request.CollectedDataRecordPageListReqDTO;
import com.huaxin.device.dto.request.CollectedDataRecordUpdateReqDTO;
import com.huaxin.device.models.CollectedDataRecord;
import com.huaxin.device.service.CollectedDataRecordService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@Tag(name = "采集数据记录")
@RestController
@RequiredArgsConstructor
@RequestMapping("/v1/device/collectedDataRecord")
public class CollectedDataRecordController {

    private final CollectedDataRecordService service;

    @Operation(summary = "创建采集数据记录")
    @PostMapping("/create")
    public ResponseResult<CollectedDataRecord> create(@RequestBody @Valid CollectedDataRecordCreateReqDTO in) {
        return service.create(in);
    }

    @Operation(summary = "获取采集数据记录详情")
    @GetMapping("/get")
    public ResponseResult<CollectedDataRecord> get(
            @Parameter(description = "记录ID", example = "rec-001")
            @RequestParam("id") String id) {
        CollectedDataRecord record = service.getByRecordId(id);
        return ResponseResult.ok(record);
    }

    @Operation(summary = "更新采集数据记录")
    @PostMapping("/update")
    public ResponseResult<String> update(@RequestBody @Valid CollectedDataRecordUpdateReqDTO in) {
        return service.update(in);
    }

    @Operation(summary = "删除采集数据记录")
    @DeleteMapping("/{id}/delete")
    public ResponseResult<String> delete(@PathVariable String id) {
        return service.delete(id);
    }

    @Operation(summary = "分页查询采集数据记录")
    @PostMapping("/page")
    public ResponseResult<IPage<CollectedDataRecord>> pageQuery(@RequestBody @Valid CollectedDataRecordPageListReqDTO in) {
        return service.pageQuery(in);
    }
}